#!usr/bin/env python3
#-*- coding: utf-8 -*- 
# https://zhuanlan.zhihu.com/p/31372146 
# 微调框1

import sys
from PyQt5.QtWidgets import QApplication,QMainWindow,QSpinBox,QLineEdit,QCompleter,QDialog
from PyQt5.Qt import pyqtSignal,pyqtSlot,QStandardItemModel
from PyQt5.QtCore import QMetaObject


class MyMainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setGeometry(350,200,500,400)
        self.initUI()

    def initUI(self):
        QMetaObject.connectSlotsByName(self) #执行这个 就可以根据 setObjectName 属性名搜索装饰器定义的信号槽(依然无效)
        #文本设置自动完成选项
        self.lineEdit_7 = QLineEdit(self)
        self.lineEdit_7.setObjectName("lineEdit_7")
        self.lineEdit_7.move(50,100)
        self.lineEdit_7.textChanged.connect(self.on_lineEdit_7_textChanged)

        self.model = QStandardItemModel(0,1,self)
        comp = QCompleter(self.model,self)
                
        self.lineEdit_7.setCompleter(comp)
        comp.activated[str].connect(self.onEmailChoosed)        
        
        

    def onEmailChoosed(self,email):
        self.lineEdit_7.setText(email)

    def on_lineEdit_7_textChanged(self,text):
        print("text",text) #始终不执行 不知道为什么在文本框内输入不触发这个槽函数,看着和你的源码没啥区别
        emaillist = [ "@163.com" , "@qq.com" , "@gmail.com" , "@live.com" , "@126.com", "@139.com"]
        self.model.removeRows(0, self.model.rowCount())
        for i in range(0, len(emaillist)):
            self.model.insertRow(0)
            self.model.setData(self.model.index(0, 0), text + emaillist[i])


    def initSpin(self):
        self.spin = QSpinBox()
        self.spin.move(50,50)
        self.spin.setSpecialValueText("特殊值") #当当前值等于最小值时显示
        self.spin.setPrefix("boss血量 ") #设置前缀
        self.spin.setSuffix(" %了你快点啊") #设置显示后缀
        self.spin.adjustSize()
        self.spin.valueChanged.connect(self.onSpinCahnge)
    def onSpinCahnge(self): 
        print(self.spin.value())

if __name__=="__main__":
    app = QApplication(sys.argv)
    win = MyMainWindow()
    win.show()
    sys.exit(app.exec())

#2019年4月19日20:48:19 PyQt5文本输入系列->单行输入->文本输入栏（QLineEdit）4